
package com.jomoo.css.common.core.constant.enums;

public enum ErrorCode {

    /*
     * 公共异常
     */
    SYS_UNKNOWN(40000001, "未知异常"),
    SYS_SYSTEM(40000002, "系统异常"),
    SYS_PARAM(40000003, "参数异常"),
    SYS_TIMEOUT(40000004, "处理超时"),
    SYS_TIMEOUT_CONNECT(40000005, "连接超时"),
    SYS_TIMEOUT_SOCKET(40000006, "链接超时"),
    SYS_MESSAGE(40000007, "其他"),
    SYS_EXPORT(40000008, "导出失败"),
    SYS_EXCEPTION(40000009, "代码抛出的异常"),
    SYS_PERMISSION(40000010,"用户权限不足"),
    SYS_UPDATE(40000011,"修改数据异常"),
    SYS_DATA_UPDATE_BY_OTHER_USER(40020012,"数据已经被其他用户更新，无法执行此次操作"),
    SYS_HYSTRIX(40000012,"HYSTRIX熔断异常"),
    SYS_FEIGN(40000013,"FEIGN远程调用异常"),
    SYS_OAUTH2(40000014,"OAuth2授权异常"),
	SYS_BUSINESS(40000015,"OAuth2授权异常"),
    //用户相关
    USER_NOT_FROUND(40025001,"用户不存在"),
    USER_PASSWORD_ERROR(40025002,"用户密码错误"),
    USER_TOKEN_NOT_EXIST(40025003,"Token不存在或验证错误"),
    USER_TOKEN_EXPIRED(40025004,"Token过期"),
    USER_REFRESH_TOKEN_EXPIRED(40025005,"Refresh Token过期"),
    USER_LDAP_FAIL(40025006,"ldap认证失败"),
    USER_UNLOGIN(40025007,"用户未登陆"),
    USER_CREATE_USER_VIEW_FAILED(40025008,"创建用户私有视图失败！"),
    USER_EXIST(40025009,"用户名已经存在，请更换用户名"),
    USER_TOKEN_NULL(40025010,"请求中Token为空"),

    SMS_CODE_ERROR(40011001, "验证码错误"),

    //角色相关
    ROLE_EMPTY(40026001,"角色不能为空"),
    ROLE_USER_EMPTY(40026002,"用户不能为空"),
    ROLE_USER_EXIST(40026003,"该角色已经存在某个用户"),
    ROLE_TEAM_EXIST(40026004,"该角色已经存在某个Team"),
    ROLE_TEAM_EMPTY(40026005,"Team不能为空"),
    ROLE_MEMBER_EMPTY(40026006,"角色成员不能为空"),
    ROLE_MEMBER_EXIST(40026007,"该角色已经存在某个成员"),
    ROLE_MENU_VALID(40026008,"所选菜单的父级菜单没有该角色权限"),
    ROLE_MODULE_EMPTY(40026009,"模块不能为空"),
    ROLE_EXIST(40026010,"角色名重复"),
    ROLE_USER_ROLE_NOT_EXIST(40026011,"对不起，您还未拥有系统角色,请联系管理员进行配置"),

    //DAEMON
	DAEMON_EXCEPTION(40110001,"定时任务异常")

	;
    private final int value;

    private final String message;

    ErrorCode(int value, String message) {
        this.value = value;
        this.message = message;
    }

    public int getValue() {
        return value;
    }

    public String getMessage() {
        return message;
    }

    @Override
    public String toString() {
        return Integer.toString(value);
    }

    public String getCode() {
        return Integer.toHexString(this.value).toUpperCase();
    }

    public String getSystem() {
        return Integer.toHexString(this.value >>> 24).toUpperCase();
    }

    public String getModule() {
        return Integer.toHexString(this.value >>> 16).toUpperCase();
    }

    /**
     * 通过枚举code获取枚举对象
     */
    public static ErrorCode getByValue(int value){
        for(ErrorCode _enum : values()){
            if(_enum.getValue() == value){
                return _enum;
            }
        }
        return null;
    }

    /**
     * 根据code获取枚举对象
     */
    public static ErrorCode getByCode(String code){
        for(ErrorCode _enum : values()){
            if(_enum.getCode().equals(code)){
                return _enum;
            }
        }
        return null;
    }
}